package bma.common.netty.handler;

import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.jboss.netty.channel.group.ChannelGroup;

public class ChannelHandlerGroup extends SimpleChannelUpstreamHandler {

	private ChannelGroup group;

	public ChannelHandlerGroup() {
		super();
	}

	public ChannelHandlerGroup(ChannelGroup group) {
		super();
		this.group = group;
	}

	public ChannelGroup getGroup() {
		return group;
	}

	public void setGroup(ChannelGroup group) {
		this.group = group;
	}

	@Override
	public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
			throws Exception {
		if (group != null) {
			this.group.add(e.getChannel());
		}
		super.channelOpen(ctx, e);
	}

}
